import PageWrapper from "@/components/PageWrapper";
import styles from "./question.module.scss";
import Router from "next/router";
import { Button } from "antd";

export default function Success(reqBody: any = {}) {
  const { questionId, answerId } = reqBody;

  return (
    <PageWrapper title="成功">
      <div style={{ marginTop: "50%", textAlign: "center" }}>
        <h2>成功</h2>
        <p>答卷提交成功</p>
        <div className={styles["button-wrapper"]}>
          {answerId && answerId !== "undefined" ? (
            <Button
              type="primary"
              onClick={() =>
                Router.push(
                  `/prompt/${questionId}${
                    answerId ? "?answerId=" + answerId : ""
                  }`
                )
              }
            >
              查看提示答案
            </Button>
          ) : (
            <Button type="primary" onClick={() => Router.back()}>
              返回
            </Button>
          )}
        </div>
      </div>
    </PageWrapper>
  );
}

export async function getServerSideProps(context: any) {
  const { questionId, answerId } = context.query;

  return {
    props: { questionId, answerId },
  };
}
